//
//  StarController.m
//  UEAssistant
//
//  Created by mac on 2017/4/13.
//  Copyright © 2017年 youyixinxi. All rights reserved.
//

#import "StarController.h"
#import "YZSortCell.h"

extern NSString * const YZUpdateMenuTitleNote;
static NSString * const ID = @"cell";

@interface StarController ()
@property (nonatomic, copy) NSArray *titleArray;

@property (strong, nonatomic) IBOutlet UITableView *tableview;
// 记录选中的cell
@property (nonatomic, assign) NSInteger selectedCol;
@end

@implementation StarController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:_selectedCol inSection:0];
    [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _titleArray = @[@"不限",@"一星级",@"二星级",@"三星级",@"四星级",@"五星级"];
    _selectedCol = 0;
    [self.tableView registerClass:[YZSortCell class] forCellReuseIdentifier:ID];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.titleArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YZSortCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    cell.textLabel.text = _titleArray[indexPath.row];
    if (indexPath.row == 0) {
        [cell setSelected:YES animated:NO];
    }
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    _selectedCol = indexPath.row;
    NSString *type = _titleArray[indexPath.row];
    if (self.didSelectSectionHandler != nil) {
        self.didSelectSectionHandler(type);
    }

    // 更新菜单标题
    [[NSNotificationCenter defaultCenter] postNotificationName:YZUpdateMenuTitleNote object:self userInfo:@{@"title":@"星级"}];
    
    
}

- (void)setDidSelectDayHandler:(DidSelectSectionHandler)didSelectSectionHandler {
    
    _didSelectSectionHandler = didSelectSectionHandler;
    self.didSelectDayHandler = _didSelectSectionHandler; // 传递 block
    
}


@end
